package com.whzm.mq;

import com.whzm.config.DelayQueueConfig;
import com.whzm.mapper.MemberOrderMapper;
import com.whzm.pojo.MemberOrder;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;


@Component
@Transactional
public class DelayListener {
    @Autowired
    MemberOrderMapper memberOrderMapper;

/**监听工作队列，如果未支付，则删除该订单*/
    @RabbitListener(queuesToDeclare = @Queue(DelayQueueConfig.DELAY_PROCESS_QUEUE_NAME))
    public void creatCoupon(String id){
        MemberOrder memberOrder=memberOrderMapper.getOrderById(id);
        if(!StringUtils.isEmpty(memberOrder)){
            if("0".equals(memberOrder.getStatus())){
                int i=memberOrderMapper.deleteById(id,1);
                if(i==1){
                    System.out.println(id+"号订单已过期，状态修改成功");
                }
            }else {
                System.out.println(id+"号订单已支付，无序修改");
            }
        }
    }

}
